/**     
* @Title: FrontendApplication.java   
* @Package me.cloud   
* @Description: TODO   
* @author xaoyaoyao
* @date 2018年12月2日 上午11:16:32
*/
package me.cloud;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

/**
 * @ClassName: FrontendApplication
 * @Description: TODO
 * @author xaoyaoyao
 * @date 2018年12月2日 上午11:16:32
 * 
 */
@EnableAutoConfiguration
@RestController
@CrossOrigin // So that javascript can be hosted elsewhere
public class FrontendApplication {

	@Autowired
	RestTemplate restTemplate;

	String backendBaseUrl = System.getProperty("spring.example.backendBaseUrl", "http://localhost:9000");

	@RequestMapping("/")
	public String callBackend() {
		return restTemplate.getForObject(backendBaseUrl + "/api", String.class);
	}

	@Bean
	RestTemplate restTemplate() {
		return new RestTemplate();
	}

	public static void main(String[] args) {
		SpringApplication.run(FrontendApplication.class, "--spring.application.name=frontend", "--server.port=8081");
	}
}
